package bud.web.shop.service;

import java.util.List;

import javax.inject.Inject;

import bud.web.shop.dao.IShopDao;
import bud.vo.BoardFormDTO;
import bud.vo.ShopDTO;

public class ShopServiceImpl implements IShopService {
//	private static ShopServiceImpl service;
//	private ShopServiceImpl(){}
//	public static ShopServiceImpl getInstance() {
//		if(service==null) {
//			service =  new ShopServiceImpl();
//		}
//		return service;
//	}
	IShopDao dao;
	
	public IShopDao getDao() {
		return dao;
	}

	public void setDao(IShopDao dao) {
		this.dao = dao;
	}

	public List<ShopDTO> getShopList() {
		
		List<ShopDTO> shopList = dao.getShopList();
		//Dao로부터 받은 원천 데이터를 가공해서 클라이언트가 요구하는 정보로 만들어줌
		return shopList;
	}

	@Override
	public ShopResult createShop(ShopDTO shop) {
		//먼저 클라이언트가 입력한 회원아이디가 이미 사용중인지 여부를 체크 
			int result = dao.insertShop(shop);
			if(result>=1) {
				return ShopResult.OK;
			} else {
				return ShopResult.Failed;
			}			
	}

	@Override
	public ShopDTO getShop(int sh_no) {
		// TODO Auto-generated method stub
		return dao.getShop(sh_no);
	}

	@Override
	public ShopResult modifyShop(ShopDTO shop) {
//		int sh_no = shop.getSh_no();
//		ShopDTO tempShop = dao.getShop(sh_no);
//		if(tempShop==null) {	//입력한 아이디에 해당하는 회원이 존재하지 않음
//			return ShopResult.NOTEXIST;
//		} else {
//			if(tempShop.getSh_pass().equals(shop.getSh_pass())) {
				int result = dao.updateShop(shop);
				if(result>=1) {
					return ShopResult.OK;
				} else {
					return ShopResult.Failed;
				}
//			} else {
//				return ShopResult.INVALIDPASSWORD;
//			}
//		}
	}

	@Override
	public ShopResult removeShop(ShopDTO shop) {
		int sh_no = shop.getSh_no();
		ShopDTO tempShop = dao.getShop(sh_no);
		if(tempShop==null) {	
			return ShopResult.NOTEXIST;
		} else {
			if(tempShop.getSh_pass().equals(shop.getSh_pass())) {
				int result = dao.deleteShop(sh_no);
				if(result>=1) {
					return ShopResult.OK;
				} else {
					return ShopResult.Failed;
				}
			} else {
				return ShopResult.INVALIDPASSWORD;
			}
		}
	}
}	
